#include<bits/stdc++.h>
using namespace std;
bool a[105];
int b[105];
int n;
int query()
{
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        //cout<<a[i]<<" ";
        for(int j=i-1;j>=1;j--)
        {
            if(a[i]==a[j])
            {
               if(b[i]==b[j])
               {
                   cnt+=b[i];
                   //cout<<"??:"<<b[i]<<"??"<<cnt;
                   break;
               }
               else
               {
                   break;
               }
            }
        }
    }
    //cout<<endl;
    return cnt;
}
int dfs(int d)
{
    if(d==n)
    {
        a[d]=1;
        int x=query();
        a[d]=0;
        int y=query();
        return max(x,y);
    }
    a[d]=1;
    int x=dfs(d+1);
    a[d]=0;
    int y=dfs(d+1);
    return max(x,y);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        //cin>>n;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",b+i);
            //cin>>b[i];
        }
        int ans=dfs(2);
        printf("%d\n",ans);
        //cout<<ans<<endl;
    }
    return 0;
}
